package com.imti.mall.order.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.imti.mall.model.user.pojo.UmsMemberReceiveAddress;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MemberReceiveAddressMapper extends BaseMapper<UmsMemberReceiveAddress> {

    /**
     * 根据会员id查询会员地址
     * @param memberId 会员id
     * @return 可能为多条 可能为一条地址
     */
    @Select("select id,member_id,name,phone_number,default_status,post_code,province,city,region,detail_address from ums_member_receive_address where member_id=#{memberId} ")
    @Results({
            @Result(id=true,property = "id",column = "id"),
            @Result(property = "memberId",column = "member_id"),
            @Result(property = "name",column = "name"),
            @Result(property = "phoneNumber",column = "phone_number"),
            @Result(property = "defaultStatus",column = "default_status"),
            @Result(property = "postCode",column = "post_code"),
            @Result(property = "province",column = "province"),
            @Result(property = "city",column = "city"),
            @Result(property = "region",column = "region"),
            @Result(property = "detailAddress",column = "detail_address")
    })
    List<UmsMemberReceiveAddress> memberReceiveAddressList(Long memberId);

    /**
     * 根据会员id查询会员的默认地址
     * @param memberId 会员id
     * @return 返回结果为一条对象
     */
    @Select("select id,member_id,name,phone_number,default_status,post_code,province,city,region,detail_address from ums_member_receive_address where default_status=1 and member_id=#{memberId} ")
    @Results({
            @Result(id=true,property = "id",column = "id"),
            @Result(property = "memberId",column = "member_id"),
            @Result(property = "name",column = "name"),
            @Result(property = "phoneNumber",column = "phone_number"),
            @Result(property = "defaultStatus",column = "default_status"),
            @Result(property = "postCode",column = "post_code"),
            @Result(property = "province",column = "province"),
            @Result(property = "city",column = "city"),
            @Result(property = "region",column = "region"),
            @Result(property = "detailAddress",column = "detail_address")
    })
    UmsMemberReceiveAddress memberReceiveAddress(Long memberId);
}
